'\" te
.\" Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
.\" Copyright (c) 1983 Regents of the University of California.  All rights reserved.  The Berkeley software License Agreement specifies the terms and conditions for redistribution.  Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved.
.TH GETHOSTNAME 3C "Feb 7, 2015"
.SH NAME
gethostname, sethostname \- get or set name of current host
.SH SYNOPSIS
.LP
.nf
#include <unistd.h>

\fBint\fR \fBgethostname\fR(\fBchar *\fR\fIname\fR, \fBint\fR \fInamelen\fR);
.fi

.LP
.nf
\fBint\fR \fBsethostname\fR(\fBchar *\fR\fIname\fR, \fBint\fR \fInamelen\fR);
.fi

.SH DESCRIPTION
.LP
The \fBgethostname()\fR function returns the standard host name for the current
machine, as previously set by \fBsethostname()\fR. The  \fInamelen\fR
argument specifies the size of the array pointed to by \fIname\fR. The returned
name is null-terminated unless insufficient space is provided.
.sp
.LP
The \fBsethostname()\fR function sets the name of the host machine to be
\fIname\fR, which has length \fInamelen\fR. This call is restricted to the
superuser and is normally used only when the system is bootstrapped.
.sp
.LP
Host names are limited to \fBMAXHOSTNAMELEN\fR characters, currently 256,
defined in the <\fBnetdb.h\fR> header.
.SH RETURN VALUES
.LP
Upon successful completion, \fBgethostname()\fR and \fBsethostname()\fR return
0. Otherwise, they return \(mi1 and set \fBerrno\fR to indicate the error.
.SH ERRORS
.LP
The \fBgethostname()\fR and \fBsethostname()\fR functions will fail if:
.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 10n
The \fIname\fR or \fInamelen\fR argument gave an invalid address.
.RE

.sp
.LP
The \fBsethostname()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEPERM\fR\fR
.ad
.RS 9n
The {\fBPRIV_SYS_ADMIN\fR} privilege was not asserted in the effective set of
the calling process.
.RE

.SH ATTRIBUTES
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Standard
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.LP
.BR sysinfo (2),
.BR uname (2),
.BR gethostid (3C),
.BR attributes (7),
.BR standards (7)
